package com.demo05.socket.m2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: root
 * @Date: 2018/11/25 1:45
 */
public class Server {
    final static int PORT = 8766;

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        BufferedReader br = null;
        try {
            serverSocket = new ServerSocket(PORT);
            System.out.println("server starting..............");
//            进行阻塞
            Socket socket = serverSocket.accept();
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            String info = null;
            while (true) {
                info = br.readLine();
                if (info == null) {
                    break;
                }
                System.out.println("我是server,得到client的数据是：" + info);
                out.println("服务器端回送响的应数据.");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
